1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * @addtogroup Bitmap 19 * @{ 20 */ 21 22 /** 23 * @file bitmap.h 24 */ 25 26 module android.ndk.bitmap; 27 28 import arsd.jni; 29 import android.ndk; 30 31 extern (C): 32 nothrow: 33 @nogc: 34 35 /** AndroidBitmap functions result code. */ 36 enum 37 { 38 /** Operation was successful. */ 39 ANDROID_BITMAP_RESULT_SUCCESS = 0, 40 /** Bad parameter. */ 41 ANDROID_BITMAP_RESULT_BAD_PARAMETER = -1, 42 /** JNI exception occured. */ 43 ANDROID_BITMAP_RESULT_JNI_EXCEPTION = -2, 44 /** Allocation failed. */ 45 ANDROID_BITMAP_RESULT_ALLOCATION_FAILED = -3 46 } 47 48 /** Backward compatibility: this macro used to be misspelled. */ 49 enum ANDROID_BITMAP_RESUT_SUCCESS = .ANDROID_BITMAP_RESULT_SUCCESS; 50 51 /** Bitmap pixel format. */ 52 enum AndroidBitmapFormat 53 { 54 /** No format. */ 55 ANDROID_BITMAP_FORMAT_NONE = 0, 56 /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/ 57 ANDROID_BITMAP_FORMAT_RGBA_8888 = 1, 58 /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/ 59 ANDROID_BITMAP_FORMAT_RGB_565 = 4, 60 /** Deprecated in API level 13. Because of the poor quality of this configuration, it is advised to use ARGB_8888 instead. **/ 61 ANDROID_BITMAP_FORMAT_RGBA_4444 = 7, 62 /** Alpha: 8 bits. */ 63 ANDROID_BITMAP_FORMAT_A_8 = 8 64 } 65 66 /** Bitmap info, see AndroidBitmap_getInfo(). */ 67 struct AndroidBitmapInfo 68 { 69 /** The bitmap width in pixels. */ 70 uint width; 71 /** The bitmap height in pixels. */ 72 uint height; 73 /** The number of byte per row. */ 74 uint stride; 75 /** The bitmap pixel format. See {@link AndroidBitmapFormat} */ 76 int format; 77 /** Unused. */ 78 uint flags; // 0 for now 79 } 80 81 /** 82 * Given a java bitmap object, fill out the AndroidBitmapInfo struct for it. 83 * If the call fails, the info parameter will be ignored. 84 */ 85 int AndroidBitmap_getInfo ( 86 JNIEnv* env, 87 jobject jbitmap, 88 AndroidBitmapInfo* info); 89 90 /** 91 * Given a java bitmap object, attempt to lock the pixel address. 92 * Locking will ensure that the memory for the pixels will not move 93 * until the unlockPixels call, and ensure that, if the pixels had been 94 * previously purged, they will have been restored. 95 * 96 * If this call succeeds, it must be balanced by a call to 97 * AndroidBitmap_unlockPixels, after which time the address of the pixels should 98 * no longer be used. 99 * 100 * If this succeeds, *addrPtr will be set to the pixel address. If the call 101 * fails, addrPtr will be ignored. 102 */ 103 int AndroidBitmap_lockPixels (JNIEnv* env, jobject jbitmap, void** addrPtr); 104 105 /** 106 * Call this to balance a successful call to AndroidBitmap_lockPixels. 107 */ 108 int AndroidBitmap_unlockPixels (JNIEnv* env, jobject jbitmap); 109 110 /** @} */